﻿<template>
    <el-radio-group v-bind="$myProps"
                    v-on="$myListeners">
        <form-radio v-for="(radio,index) in myOptions"
                  :key="index"
                  :display="display"
                  :label="radio[props.value]">{{$t(radio[props.label])}}</form-radio>
    </el-radio-group>
</template>

<script>
    export default {
        components: {
            formRadio: () => import('./radio')
        },
        props: {
            //单选值
            value: [String, Number, Boolean],
            //选项列表
            options: {
                type: [Array, Function, Object],
                required: true
            },
            display: {
                type: String,
                default: 'button'
            },
            //选项属性定义
            props: {
                type: Object,
                default () {
                    return {
                        label: 'label',
                        value: 'value'
                    }
                }
            },
            objSource: {
                type: [Object]
            }
        },
        computed: {
            $myProps () {
                return this.$public.inheritProps(this)
            },
            $myListeners () {
                return this.$public.inheritListeners(this)
            },
            myOptions () {
                var objSource = this.objSource || this.options;

                let options =this.$core.convertOptions({
                    options: this.options,
                    props: this.props,
                    objSource
                })

                return options
            }
        },
        mounted () {
            this.$emit('mounted')
        },
        created () {
            this.$emit('created')
        }
    }
</script>